<?php
/*
 * Created on 14.10.2007
 * filename: startup.php5
 * 
 * this class - autoloader - loads requested classes
 * 
 */

 if(version_compare(phpversion(),'5.1.0','<')) {
	die('require PHP5.1');
 }
 // load config
 include('config.php5'); 
 // load check input params function
 include(COREPATH.'libs/sanitize_vars.php');
 // load character convert function
 include(COREPATH.'libs/Utf8Win.php');
 // load smarty class
 include(COREPATH.'libs/Smarty/libs/Smarty.class.php'); 

 function __autoload($class_name) {
	
	$current_class_file = site_path . 'classes' . DIRSEP . strtolower($class_name).ext;


 	if(preg_match("/Model_([^_]*)(?:_([^_]*))?/", $class_name, $matches) ) {
		// loading models
		array_shift($matches);
		$file = COREPATH . 'models' . DIRSEP . strtolower(join('/',$matches)).ext;
 	
 	} else if(ereg("Exception", $class_name) ) {
 		// loading exceptions
 		$filename = strtolower(preg_replace("/(.*)Exception$/", "$1", $class_name )).ext;
 		$file = COREPATH . 'classes/exceptions' . DIRSEP . $filename;
    
 	} else if (file_exists($current_class_file)) {
 		// loading classes for current instance	
 		$file = $current_class_file;
    } else {
		// loading core classes
	 	$filename = strtolower($class_name).ext;
 		$file = COREPATH . 'classes' . DIRSEP . $filename;
 	}

 	if(!file_exists($file)) {
 		
 		$name = split ("_",$class_name);
 		
 		$file = site_path.'plugins/'.strtolower($name[1]).ext;
		
		if(!file_exists($file)) {
			return false;	
		}
 		
 	}
	 	
 	include ($file);
 }

?>
